package org.zjt.platform.demo.api;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate;
import org.zjt.platform.demo.entity.TestPOJO;
import org.zjt.platform.demo.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * Created by zhang on 2016/12/8.
 */
@ApiIgnore
@RestController
@RequestMapping("/")
@SuppressWarnings("all")
public class TestController {
    private  static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private ITestService testService;


    @GetMapping(value = "list")
    public List<TestPOJO> test(@RequestParam(value = "age",required = true)Long age){
        Assert.notNull(age,"age is empty");
        if (LOGGER.isDebugEnabled())
            LOGGER.info("ssssssssssss       {}           ssssss","1111111111");
        if (LOGGER.isErrorEnabled())
            LOGGER.error("ssssssssssss       {}           ssssss","1111111111");
        return testService.get(age);
    }

    @GetMapping //@GetMapping
    public List<TestPOJO> index(@RequestParam(value = "age",required = true)Long age)throws Exception{
        Assert.notNull(age,"age is empty");

        TestPOJO pojo = new TestPOJO();
        pojo.setAge(120);
        pojo.setName("lllllll");
        pojo.setId(1L);
        testService.updateUser(pojo);

        return testService.get(age);
    }



    @PutMapping //@GetMapping
    public List<TestPOJO> update(@RequestParam(value = "id",required = true)Long id)throws Exception{
        Assert.notNull(id,"age is empty");

        TestPOJO pojo = new TestPOJO();
        pojo.setName("lllllll");
        pojo.setId(id);
        testService.concurrentUpdata(pojo);

        return testService.get(id);
    }

    public static void main(String[] args) {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.put("http://localhost:8080/boot-demo/?id={id}",null,"1");
    }



}
